package main.od;

import java.util.Arrays;
import java.util.Scanner;

public class MaxSpendTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] m = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int r = sc.nextInt();
        int n = m.length;
        Arrays.sort(m);
        int sum = 0;
        for (int i = n - 1;i >= 2;i--){
            if (m[i] > r){
                continue;
            }
            for (int j = i - 1;j >= 1;j--){
                if (m[i] + m[j] > r){
                    continue;
                }
                for (int k = j - 1;k >= 0;k--){
                    int temp = m[i] + m[j] + m[k];
                    if(temp <= r && temp > sum){
                        sum = temp;
                    }
                }
            }
        }
        System.out.println(sum == 0 ? -1 : sum);
    }
}
